<template>
  <ex-dialog
    width="900px"
    class="ex-diolog"
    :title="title"
    :visible="visible"
    @closeDialog="handleClose"
  >	
		<el-table v-loading="loading" :data="customerList" stripe border>
      <el-table-column label="序号" type="index" width="55" align="center" fixed />
      <el-table-column label="用户昵称" align="center" prop="nickName" :show-overflow-tooltip="true" />
      <el-table-column label="手机号" align="center" prop="phone" :show-overflow-tooltip="true"/>
      <el-table-column label="评论内容" align="center" prop="content" :show-overflow-tooltip="true"/>
      <el-table-column label="评论时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleShow(scope.row)" v-if="scope.row.status == 1">
            隐藏</el-button> 
          <el-button size="mini" type="text" @click="handleShow(scope.row)" v-if="scope.row.status == 2">
            显示</el-button> 
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" />
  </ex-dialog>
</template>
<script>
// components
import Loading from '@/components/Loading/index'
// api
import {
  newsCommentList,
  changeStatus
} from "@/api/kyyOfficialWebsite/newsManagement";

export default {
  components: {
    Loading
  },
  props: {
    visible: Boolean,
    id: String,
  },
  data() {
    
    return {
      loading: false,
      title: '快讯评论',
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        newsId: '',
      },
      customerList: [],
    }
  },
  computed: {
   
  },
  created() {
    this.queryParams.newsId = this.id
    this.getList()
	},
  methods: {
    //列表
    getList() {
      this.loading = true;
      newsCommentList(this.queryParams).then(response => {
        this.total = response.result.total
          this.customerList = response.result.records
          this.customerList = this.customerList.map(item => {
            // console.log('item',item)
            Object.keys(item).forEach(key => {
              if (item[key] === '') {
                item[key] = '-'
              }
            })
            return item
          })
          
          this.loading = false;
        
      }).finally(()=>{
        this.loading = false;
      })
    },
    //显示/隐藏
    handleShow(row){
      console.log('row',row)
      if(row.status == 1){
        var title = '是否前端隐藏'
      }else if(row.status == 2){
        var title = '是否前段显示'
      }
      console.log('title',title)
      this.$confirm(title, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          changeStatus(row.id).then(res => {
            this.$message.success('操作成功')
            this.getList()
          })
        }).catch(() => {});
    },
    
		//取消
    handleClose(formName) {
      this.$emit('update:visible', false)
			// this.$refs[formName].resetFields();
    },
		//确认
		handleConfirm(){
			this.$emit('success', '你好')
		},
    handleSuccess(msg) {
      if (msg === '已拒绝') {
        var type = 'error'
      } else {
        var type = 'success'
      }
      this.$message({
        message: msg,
        type: type,
        duration: 1000,
        onClose: () => {
          this.handleClose()
          this.$emit('success')
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
		padding: 0 !important;
  }
	::v-deep .ex--dialog--main {
    padding: 10px 20px !important; 
  }
}
</style>